//package com.tiancheng.trade.order.util.cmq.queue.consumer;
//
//import com.alibaba.fastjson.JSON;
//import com.tiancheng.trade.commom.core.exception.BusinessException;
//import com.tiancheng.trade.commom.core.exception.error.BusinessErrorInfoEnum;
//import com.tiancheng.trade.commom.core.utils.JsonUtil;
//import com.tiancheng.trade.order.bo.cmq.OrderStateChangeMsgBo;
//import com.tiancheng.trade.commom.core.enums.MessageTypeEnum;
//import com.tiancheng.trade.order.service.SubOrderService;
//import com.tiancheng.trade.order.util.EnumUtil;
//import com.tiancheng.trade.order.util.cmq.MessageParsing;
//import com.tiancheng.trade.commom.core.data.MessageBody;
//import com.tiancheng.trade.order.util.cmq.model.QueueMessage;
//import jakarta.annotation.Resource;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//
///**
// * @Author: likailun
// * @Description: 订单状态处理
// * @Date: create in 2021/9/15 9:59 上午
// */
//@Slf4j
//@Component
//public class OrderStateQueueConsumer extends AbstractCustomQueueConsumer {
//
//
//    //@Value(value = "${mq.order-state-queue}")
//    private String orderStateQueue="";
//    @Resource
//    private MessageParsing messageParsing;
//    @Resource
//    private SubOrderService subOrderService;
//
//
//    @Override
//    public void handle(QueueMessage message) throws Exception {
//        // 实现逻辑
//        MessageBody msgBody = messageParsing.getQueueBody(message.getMsgBody());
//        String messageType = msgBody.getMessageType();
//        if (StringUtils.isEmpty(messageType)) {
//            messageType = msgBody.getCmdStr();
//        }
//
//        MessageTypeEnum msgType = EnumUtil.getEnumByCode(MessageTypeEnum.class, messageType);
//        if (msgType == null) {
//            throw new RuntimeException("未查询到指定消息类型");
//        }
//        switch (msgType) {
//            case order_sub_status_change:
//                final OrderStateChangeMsgBo bo = JsonUtil.fromJson(JsonUtil.toJsonString(msgBody.getData()), OrderStateChangeMsgBo.class);
//                log.info("子订单状态流转处理:{}", JSON.toJSONString(message));
//                if (null != bo && !StringUtils.isEmpty(bo.getOrderId()) && !StringUtils.isEmpty(bo.getBizStatus())) {
//                    try {
//                        subOrderService.statusFlow(bo.getOrderId(), bo.getSubOrderIds(), bo.getBizStatus());
//                    } catch (BusinessException e) {
//                        if (e.getErrorInfo() != null && (e.getErrorInfo().getCode() == BusinessErrorInfoEnum.ORDER_STATUS_FLOW_NO_DATA.getCode())) {
//                            log.error("处理状态消息失败失败，未查询到订单或对应的状态,message:{}", JsonUtil.logToJson(bo));
//                            break;
//                        }
//                        log.error("处理状态消息失败失败,message:{},error:", JsonUtil.logToJson(bo), e);
//                        throw e;
//                    }
//                }
//                break;
//            default:
//                log.warn("未知的消息类型：{}", msgType);
//        }
//    }
//
//    @Override
//    public int getPullInterval() {
//        // 轮训间隔时间1s
//        return 1000;
//    }
//    @Override
//    public Integer getPollingWaitSeconds() {
//        return 5;
//    }
//    @Override
//    public String getQueueName() {
//        return orderStateQueue;
//    }
//}
